/*
 * FileAsMsg plug-in for Miranda IM and QIP Infium.
 * Sending/receiving files via instant messaging without protocol support.
 * Homepage: http://code.google.com/p/fileasmsg/
 *
 * Copyright (c) 2008, Radist <radist.nt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Name(s) of contributor(s) may not be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Radist ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Radist BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FILEASMESSAGE_MIRANDA_PLUGIN_H__R___

#include <Windows.h>
#pragma warning(push)
#pragma warning(disable:4996)
#include <newpluginapi.h>
#include <m_system.h>
#include <m_netlib.h>
#include <m_database.h>
#include <m_protosvc.h>
#include <m_langpack.h>
#include <m_contacts.h>
#pragma warning(pop)

extern char *pluginName;

//SHA1 interface
#define SHA1_HASH_SIZE MIR_SHA1_HASH_SIZE
#define SHA1_CTX mir_sha1_ctx
#define sha1_init(pctx) mir_sha1_init(pctx)
#define sha1_append(pctx,data,len) mir_sha1_append(pctx,data,len)
#define sha1_finish(pctx,_hash) mir_sha1_finish(pctx,_hash)

//Memory interface
#define _malloc(x) mir_alloc(x)
#define _calloc(x) mir_calloc(x)
#define _free(x) mir_free(x)
#define _realloc(x,y) mir_realloc(x,y)
#define _strdup(x) mir_strdup(x)
#define _wstrdup(x) mir_wstrdup(x)
#define _tstrdup(x) mir_tstrdup(x)
#define _a2u(x) mir_a2u(x)
#define _u2a(x) mir_u2a(x)
#define _utf8decodeW(x) mir_utf8decodeW(x)
#define _utf8encodeW(x) mir_utf8encodeW(x)

//Various services
#define SendIMMsg(hContact,msg,_utf8) (HANDLE)CallContactService(hContact, PSS_MESSAGE, (_utf8) ? PREF_UTF : 0, (LPARAM)msg)
#define ForkThread(start,param,idptr) (HANDLE)mir_forkthreadex(start, param, 0, idptr)
#define SaveWndPos(hWnd, hContact, NamePrefix) Utils_SaveWindowPosition(hWnd, hContact, pluginName, NamePrefix)
#define LoadWndPos(hWnd, hContact, NamePrefix) Utils_RestoreWindowPositionNoSize(hWnd, hContact, pluginName, NamePrefix)

inline wchar_t *GetContactName(HANDLE hContact)
{
	CONTACTINFO ci = {sizeof(CONTACTINFO), CNF_DISPLAY|CNF_UNICODE, hContact};
	if (!CallService(MS_CONTACT_GETCONTACTINFO, NULL, (LPARAM)&ci))
	{
		if (CNFT_ASCIIZ==ci.type) return ci.pszVal;
		else mir_free(ci.pszVal);
	}
	return NULL;
}

#define __FILEASMESSAGE_MIRANDA_PLUGIN_H__R___
#endif//__FILEASMESSAGE_MIRANDA_PLUGIN_H__R___
